define(['jquery', 'bootstrap', 'select2', 'validate', 'validate.en', 'koala-search', 
        'shiftform', 'modalSearch', 'datetimepicker', 'datetimepickerCN'],
        
function($, validate) {
  
  return {
    
    init: function() {
      this.initPage();
      this.initVehicle();
      this.triggerModalSearch();
    },
    
    initPage: function(){
      
    	$(document).find('form').bind('reset', function(e){
            $(this).find(".select2").select2("val", "");
      	})
        
        $(document).find('form').bt_validate();
        
        $('select[name="organizationId"]').select2({
          theme: "classic",
          placeholder : '请选择',
          minimumResultsForSearch : -1,
          allowClear : true,
        });
        
        $('.date').datetimepicker({
          format: 'yyyy-mm-dd',
          autoclose: true,
          language: 'zh-CN',
          todayBtn: 'linked',
          startDate: '${today}',
          todayHighlight: true,
          pickerPosition: 'bottom-right',
          minView: 'month'
        });
    },
    
    initVehicle:function() {
      
      $('[data-target="#modal-search-vehicle"]').modalsearch({
        url: function(){
          var url = window.__CTX__.root + '/vehicles/query';
          return url + "?companyIds=" + $("[name='organizationId']").val();
        },
        tableColumns: ['驳运车代码', '驳运车名称'],
        tableValues: ['code', 'name'],
        displayValues: ['code', 'name'],
        values: ['id']
      });
            
      var options = {
        time: 1000,
        url: window.__CTX__.root + "/vehicles/query",
        queryName: "code",
        value: ["id"],
        display: ["code", "name"]
      }
      
      $('.vehicle-search').koalaSearch(options);
      
    },
    
    triggerModalSearch: function() {
      $('.modal-search').each(function() {
        var value = $(this).val();
        console.info(value);
        if (value) {
          $(this).trigger('blur');
        }
      });
    }
    
  }
})